﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Core.Query;
using NHibernate;
using System.Collections.ObjectModel;
using NHibernate.Criterion;

namespace BonsaiScrum.Data.Reporting
{
    public class NHibernateUserRepository : IUserReportingRepository
    {
        private ISession _session;

        public NHibernateUserRepository(ISession session)
        {
            _session = session;
        }

        public UserReport GetUserWithId(int id)
        {
            return _session.Get<UserReport>(id);
        }

        public UserReport GetUserWithUserName(string userName)
        {
            UserReport user = _session.CreateCriteria<UserReport>()
                .Add(Expression.Eq("UserName", userName))
                .UniqueResult<UserReport>();

            return user;
        }


        public ICollection<UserReport> GetAllUsers()
        {
            var criteria = _session.CreateCriteria<UserReport>();
            return criteria.List<UserReport>();
        }
    }
}
